package com.zx._12_算法.数据结构.link;


/**
 * @version v1.0
 * @Project: knowledge
 * @Title: 数字生成短链
 *         从尾到头打印链表（普通模式）
 * @author: zhangxue
 * @date: 2019年7月27日下午8:34:11
 * @company: 未知之地
 * @Copyright: Copyright (c) 2019
 */
public class Demo1 {

    public static void main(String[] args) {
        Node<String> node1 = new Node<>();
        Node<String> node2 = new Node<>();
        Node<String> node3 = new Node<>();
        Node<String> node4 = new Node<>();
        Node<String> node5 = new Node<>();

        node1.data = "1";
        node1.next = node2;
        node2.data = "2";
        node2.next = node3;
        node3.data = "3";
        node3.next = node4;
        node4.data = "4";
        node4.next = node5;
        node5.data = "5";

        Node<String> node = node1;
        while (node != null) {
            System.out.println(node.data);
            node = node.next;
        }

        reversePrint(node1);
    }


    public static void reversePrint(Node<String> head) {
        if (head == null) {
            return;
        }
        reversePrint(head.next);
        System.out.println(head.data);
    }

    static class Node<T> {

        T data;
        Node<T> next;
    }
}
